home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1997 May / PC Plus Super CD Issue 127 (May 1997).iso / handson / handson.exe / CONST1.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-02-01  |  1.1 KB  |  56 lines

  1. unit Const1;
  2. { PC Plus sample Delphi program.
  3.   Show how to declare global and local Constants }
  4.  
  5. interface
  6.  
  7. uses
  8.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  9.   Forms, Dialogs, StdCtrls;
  10.  
  11. type
  12.   TForm1 = class(TForm)
  13.     ListBox1: TListBox;
  14.     Button1: TButton;
  15.     procedure Button1Click(Sender: TObject);
  16.   private
  17.     { Private declarations }
  18.   public
  19.     { Public declarations }
  20.   end;
  21.  
  22.  
  23. { Global Constants
  24.   These aren't as 'bad' as global variables since, being constant,
  25.   their values cannot change during program execution. So they can't
  26.   cause the same unexpected 'side-effects' as global variables }
  27. const
  28.   LOOPLIMIT = 4;
  29.   MAG = 'PC Plus';
  30.  
  31. var
  32.   Form1: TForm1;
  33.  
  34. implementation
  35.  
  36. {$R *.DFM}
  37.  
  38. procedure TForm1.Button1Click(Sender: TObject);
  39. const
  40.   ThisProc = 'TForm1.Button1Click'; { local const }
  41. var
  42.   i : integer;
  43. begin
  44.   With ListBox1.Items do
  45.   begin
  46.       for i := 1 to LOOPLIMIT do
  47.           Add('Loop: ' + IntToStr( i ) );
  48.       Add( 'You are reading ' + MAG );
  49.       Add( 'Current procedure is ' + ThisProc );
  50.   end;
  51. end;
  52.  
  53.  
  54.  
  55. end.
  56.